/*
 *
 * Version 1.00
 * 
 * Created on 2007-6-4
 * Encoding UTF-8
 */
package net.comm.group.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import net.comm.common.GlbFinal;
import net.comm.common.ReturnMessage;


import net.comm.friend.service.impl.LinjuServiceImpl;
import net.comm.friend.web.form.LinjuForm;
import net.comm.group.bean.BaseGroups;
import net.comm.group.service.impl.GFollForumServiceImpl;
import net.comm.group.service.impl.GForumServiceImpl;
import net.comm.group.service.impl.GMemberServiceImpl;
import net.comm.group.service.impl.GPictureServiceImpl;
import net.comm.group.service.impl.GpartyServiceImpl;
import net.comm.group.service.impl.GroupsServiceImpl;
import net.comm.group.web.form.GForumForm;
import net.comm.group.web.form.GMemberForm;
import net.comm.group.web.form.GPictureForm;
import net.comm.group.web.form.GpartyForm;
import net.comm.group.web.form.GroupsForm;
import net.comm.oper.service.impl.OperLogServiceImpl;
import net.comm.oper.web.form.OperLogForm;
import net.comm.page.PageCtr;
import net.comm.util.HtmlMessageBox;
import net.comm.web.base.AbstractBaseAction;


/**
 *群组Action
 * @author hcgong(hcgong@sina.com)
 * @version 1.0
 * @date 2007-6-4
 */
public class GroupsAction extends AbstractBaseAction {
	
	private GroupsServiceImpl service = null;
	
	/**
	 * struct-config中该ACTION中的每个forward的常量定义
	 */
	final String MYHOME_FORWARD = "myhome";
	final String INDEX_FORWARD = "index";
	final String LIST_FORWARD = "list";
	final String OPER_FORWARD = "oper";
	final String ADOPER_FORWARD = "adoper";
	final String INFO_FORWARD = "info";
	final String LOGIN_FORWARD = "loginFwd";		
	final String ZIZHU_FORWARD = "zizhu";
	
	
	/**
	 *构造方法
	 */
	public GroupsAction()
	{
		super(false);
		
		/**
		 * 初始化业务组件接口
		 */
		service = new GroupsServiceImpl();
	}
	
	/**
	 * 默认动作
	 * 1.action值为空的时候,进入查询页面
	 * 2.每个操作都执行的代码,但是方法必须返回null
	 * @param mapping	 跳转的mapping值	
	 * @param request	 HttpServletRequest对象
	 * @param response	 HttpServletResponse对象
	 */
	public ActionForward startAction(ActionMapping mapping, ActionForm form,
									 HttpServletRequest request , 
									 HttpServletResponse response)
	{
		String action = getReqParam(request , ACTION_KEY);
		if(action == null || action.trim().length() == 0) {
			return mapping.findForward(LIST_FORWARD);
		} else {
			return null;
		}
	}
	
	/**
	 * 查询群组清单
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward list(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		/**
		 *定义一个查询bean保存查询页面提交的查询条件
		 */
		GroupsForm theForm = (GroupsForm)form;
			
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,20));
		
		ReturnMessage msg  = new ReturnMessage();
		
		
		/**
		 *调用services中的方法
		 */
		List list = service.list(theForm , msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
		/**
		 *设置列表的数据
		 */
		setAction(request, "list");
		request.setAttribute("grouplist" , list);
		request.setAttribute("theForm", theForm);
		
		int len = list.size();
		StringBuffer sb = new StringBuffer();
		String title = "";
		BaseGroups base = null;
		if(len > 10)
			len = 10;
		for(int i=0; i< len; i++){
			
			base = (BaseGroups)list.get(i);
			sb.append(base.getName());
			sb.append(",");
			if(i == 2 ){
				title = sb.toString();
			}
		}
		if(title.equals("")){
			title = "贷款群组";
		}
		request.setAttribute("title", title);
		request.setAttribute("descr", sb.toString());
		
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(LIST_FORWARD);
	}
	/**
	 * 查询群组清单
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward adlist(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		/**
		 *定义一个查询bean保存查询页面提交的查询条件
		 */
		GroupsForm theForm = (GroupsForm)form;
			
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,20));
		
		ReturnMessage msg  = new ReturnMessage();
		
		/**
		 *调用services中的方法
		 */
		List list = service.adlist(theForm , msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		/**
		 *设置列表的数据
		 */
		setAction(request, "adlist");
		request.setAttribute("grouplist" , list);
		request.setAttribute("theForm", theForm);
		
		int len = list.size();
		StringBuffer sb = new StringBuffer();
		String title = "";
		BaseGroups base = null;
		if(len > 10)
			len = 10;
		for(int i=0; i< len; i++){
			
			base = (BaseGroups)list.get(i);
			sb.append(base.getName());
			sb.append(",");
			if(i == 2 ){
				title = sb.toString();
			}
		}
		if(title.equals("")){
			title = "部落";
		}
		request.setAttribute("title", title);
		request.setAttribute("descr", sb.toString());		
		
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(LIST_FORWARD);
	}

	/**
	 * 查询自助机构清单
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward zizhu(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		/**
		 *定义一个查询bean保存查询页面提交的查询条件
		 */
		GroupsForm theForm = (GroupsForm)form;
			
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,20));
		
		ReturnMessage msg  = new ReturnMessage();
		
		/**
		 *调用services中的方法
		 */
		List list = service.adlist(theForm , msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		/**
		 *设置列表的数据
		 */
		setAction(request, "zizhu");
		request.setAttribute("grouplist" , list);
		request.setAttribute("theForm", theForm);
		
		int len = list.size();
		StringBuffer sb = new StringBuffer();
		String title = "";
		BaseGroups base = null;
		if(len > 10)
			len = 10;
		for(int i=0; i< len; i++){
			
			base = (BaseGroups)list.get(i);
			sb.append(base.getName());
			sb.append(",");
			if(i == 2 ){
				title = sb.toString();
			}
		}
		if(title.equals("")){
			title = "部落";
		}
		request.setAttribute("title", title);
		request.setAttribute("descr", sb.toString());		
		
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		//取推荐群组
		List tuijianlist = service.TjGroups(0);
		request.setAttribute("tuijianlist", tuijianlist);		
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(ZIZHU_FORWARD);
	}
		
	/**
	 * 群组首页
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward myhome(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		/**
		 *定义一个查询bean保存查询页面提交的查询条件
		 */
		GroupsForm theForm = new GroupsForm();
		
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID.equals("")){
			
			return mapping.findForward(LOGIN_FORWARD);			
		}		
		theForm.setUserID(userID);
		
		//取得我管理的群和我加入的群
		GMemberServiceImpl memberservice = new GMemberServiceImpl();
		
		List grouplist = memberservice.list(theForm.getUserID());
		request.setAttribute("grouplist", grouplist);
		
		//取得我加入群的最新话题
		GForumServiceImpl forumservice = new GForumServiceImpl();
		List forumlist = forumservice.list(theForm.getUserID());
		
		request.setAttribute("forumlist", forumlist);
		
		//取得我在群发表的话题最新回复
		GFollForumServiceImpl follforumservice = new GFollForumServiceImpl();
		
		List follforumlist = follforumservice.list(theForm.getUserID());
		request.setAttribute("follforumlist", follforumlist);
		
	
		//取得我加入群的最新图片
//		GPictureServiceImpl picservice = new GPictureServiceImpl();
//		
//		List piclist = picservice.newlist(theForm.getUserID());
//		
//		request.setAttribute("piclist", piclist);
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(MYHOME_FORWARD);
	}	
	/**
	 * 群组板块
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward index(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		/**
		 *定义一个查询bean保存查询页面提交的查询条件
		 */
		GroupsForm theForm = (GroupsForm) form;
	
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,8));
		
		ReturnMessage msg  = new ReturnMessage();
		
		//取得逛群组
		theForm.setIsradnom(GlbFinal.YES);
		
		List radomlist = service.adlist(theForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("radomlist", radomlist);		
		
		//取得群组热门话题
		GForumServiceImpl forumservice = new GForumServiceImpl();
		GForumForm forumForm = new GForumForm();
		
		forumForm.setPage(this.getPageFromReq(request,5));
		
		forumForm.setQryOrderby(" Attachcnt Desc ");
		
		List hotForumlist = forumservice.adlist(forumForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("hotForumlist", hotForumlist);	
		
		//取得最新话题
		forumForm.Clear();
		forumForm.setPage(this.getPageFromReq(request,5));
		forumForm.setQryOrderby(" CTime Desc ");
		
		List newForumlist = forumservice.adlist(forumForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("newForumlist", newForumlist);	
		
	
		//群组分类数量统计
		List TotalbyFirsort = service.listGroupByFirsort();
		request.setAttribute("TotalbyFirsort" , TotalbyFirsort);

		//群组人气榜
		theForm.Clear();
		theForm.setPage(this.getPageFromReq(request,6));
		theForm.setQryOrderby(" PepoleVal desc ");
		
		List pepoleVallist = service.adlist(theForm, msg);
		
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("pepoleVallist", pepoleVallist);	
		
		//最新群组
		theForm.Clear();
		theForm.setPage(this.getPageFromReq(request,8));
		theForm.setQryOrderby(" CTime desc ");
		
		List newgroupllist = service.adlist(theForm, msg);
		
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("newgroupllist", newgroupllist);			
		
		//群组动态
		OperLogServiceImpl operservice = new OperLogServiceImpl();
		
		OperLogForm operForm = new OperLogForm();
		
		operForm.setPage(this.getPageFromReq(request,7));
		operForm.setQryType("1,3,4");
		
		List operlist = operservice.adlist(operForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("operlist", operlist);		
		
		//活跃群组成员
		operForm.setPage(this.getPageFromReq(request,8));
		operForm.setQryType("1,3,4");
		
		List hotuserlist = operservice.adlist(operForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("hotuserlist", hotuserlist);		
		
		//群组热门同城
		
		
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(INDEX_FORWARD);
	}		
	/**
	 *取群组
	 */
	public ActionForward get(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		
		ReturnMessage msg  = new ReturnMessage();
		
		service.get(theForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("theForm", theForm);

		//判断当前用户是否已经加入了该群组
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);

		String addflg = "no";
		if(userID != null){
			GMemberServiceImpl memservice = new GMemberServiceImpl();
			GMemberForm memForm = new GMemberForm();
			
			memForm.setGroupID(theForm.getGroupID());
			memForm.setUserID(userID);
			
			memservice.get(memForm, msg);
			if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS ){
				if(msg.getMsg().equals("会员不存在"))
				{
					request.setAttribute("addflg", addflg);
				}
				msg.setErrCode(GlbFinal.ERRCODE_SUCCESS);	
			}else{
				//当前用户类型（群组创建者或者管理员）
				request.setAttribute("memType", memForm.getType());
				addflg = "yes";
				request.setAttribute("addflg", addflg);
			}

			//私密群 不允许未加入访问
			if(theForm.getType().equals(GlbFinal.GROUP_SECRET) && addflg.equals("no")){
				
				HtmlMessageBox hmb = new HtmlMessageBox();
				hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
				hmb.setPrintMessage("该群组为私密群组，需要加入后才允许访问！");
				hmb.setForwardUrl("/group.do?action=list");
				return showMsg(hmb , request , response , mapping);			
			}			
		}else{
			
			request.setAttribute("addflg", addflg);
		}
		
		//取话题区
		GForumForm forumForm = new GForumForm();
		PageCtr page = new PageCtr(1, 3, "N", " 1=1 ");
		
		forumForm.setPage(page);
		forumForm.setQryGroupID(theForm.getGroupID());
		
		GForumServiceImpl forumservice = new GForumServiceImpl();
		
		msg.setErrCode(GlbFinal.ERRCODE_SUCCESS);
		List forumlist = forumservice.list(forumForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}		
		request.setAttribute("forumlist", forumlist);
		
		msg.setErrCode(GlbFinal.ERRCODE_SUCCESS);
		//取群照片
		GPictureServiceImpl picservice = new GPictureServiceImpl();
		GPictureForm picForm = new GPictureForm();
		
		picForm.setPage(new PageCtr(1, 4, "N", " 1=1 "));
		picForm.setQryGroupID(theForm.getGroupID());
		
		List piclist = picservice.list(picForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}			
		request.setAttribute("piclist", piclist);
		
		//部落活动
		GpartyServiceImpl partyservice = new GpartyServiceImpl();
		GpartyForm partyForm = new GpartyForm();
		
		partyForm.setPage(page);
		partyForm.setQryGroupID(theForm.getGroupID());
		
		List partylist = partyservice.adlist(partyForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}			
		request.setAttribute("partylist", partylist);		
		
		//取最新加入 成员
		GMemberServiceImpl memberservice = new GMemberServiceImpl();
		GMemberForm memberForm = new GMemberForm();
		
		memberForm.setPage(page);
		memberForm.setQryGroupID(theForm.getGroupID());
		memberForm.setQryType(GlbFinal.GROUPMEMBER_COMMON);

		msg.setErrCode(GlbFinal.ERRCODE_SUCCESS);

		List memberlist = memberservice.adlist(memberForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}			
		request.setAttribute("memberlist", memberlist);
		
		//取管理员和创建者
		memberForm.Clear();
		memberForm.setPage(page);
		memberForm.setQryGroupID(theForm.getGroupID());
		memberForm.setQryType(GlbFinal.GROUPMEMBER_CREATOR_MANAGER);
		
		List managerlist = memberservice.adlist(memberForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}			
		request.setAttribute("managerlist", managerlist);
		
		//取得浏览者邻居列表
		LinjuServiceImpl linjuservice = new LinjuServiceImpl();
		LinjuForm linjuform = new LinjuForm();
		
		linjuform.setPage(new PageCtr(1, 300, "N", " 1=1 "));
		linjuform.setQryUserID(userID);
		
		List linjulist = linjuservice.adlist(linjuform, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}			
		request.setAttribute("linjulist", linjulist);		
		
		
//		//取推荐群组
//		List tuijianlist = service.TjGroups(theForm.getGroupID());
//		request.setAttribute("tuijianlist", tuijianlist);

//		//取活动点评排行
//		GdpTotalServiceImpl dptotalservice = new GdpTotalServiceImpl();
//		GdpTotalForm dptotalForm = new GdpTotalForm();
////		
//		dptotalForm.setPage(new PageCtr(1, 10, "N", " 1=1 "));
//		dptotalForm.setQryGroupID(theForm.getGroupID());
//		dptotalForm.setQryDsort(GlbFinal.DSORT_PARTY);
//		
//		List dianpartylist = dptotalservice.list(dptotalForm, msg);
//		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
//		{
//			HtmlMessageBox hmb = new HtmlMessageBox();
//			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
//			hmb.setPrintMessage(msg.getMsg());
//			hmb.setForwardUrl("javascript:history.go(-1)");
//			return showMsg(hmb , request , response , mapping);
//		}			
//		request.setAttribute("dianpartylist", dianpartylist);	
//		
//		//取图片点评排行
//		dptotalForm.setPage(new PageCtr(1, 10, "N", " 1=1 "));
//		dptotalForm.setQryGroupID(theForm.getGroupID());
//		dptotalForm.setQryDsort(GlbFinal.DSORT_PIC);
//		
//		List dianpiclist = dptotalservice.list(dptotalForm, msg);
//		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
//		{
//			HtmlMessageBox hmb = new HtmlMessageBox();
//			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
//			hmb.setPrintMessage(msg.getMsg());
//			hmb.setForwardUrl("javascript:history.go(-1)");
//			return showMsg(hmb , request , response , mapping);
//		}			
//		request.setAttribute("dianpiclist", dianpiclist);		
		
		return mapping.findForward(INFO_FORWARD);
	}		
	/**
	 *我管理、创建、加入的群组
	 */
	public ActionForward mygroup(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,20));

		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0 ){
			
			return mapping.findForward(LOGIN_FORWARD);			
		}
		theForm.setQryUserID(userID);
		
		ReturnMessage msg  = new ReturnMessage();
		
		List list = service.listmyadd(theForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("grouplist", list);		
		
		request.setAttribute("theForm", theForm);
	
		setAction(request, "mygroup");
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		return mapping.findForward(LIST_FORWARD);
	}	
	
	/**
	 *群组资料维护
	 */
	public ActionForward modifyPage(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0){
			
			return mapping.findForward(LOGIN_FORWARD);			
		}
		ReturnMessage msg  = new ReturnMessage();
		
		service.get(theForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("theForm", theForm);
		
		return mapping.findForward(OPER_FORWARD);
	}
	
	/**
	 * 跳转到显示页面
	 */
	public ActionForward adaddPage(ActionMapping mapping, ActionForm form,
			 				 	 HttpServletRequest request , 
			 				 	 HttpServletResponse response)  
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		ReturnMessage msg  = new ReturnMessage();
	
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0){
			
			return mapping.findForward(LOGIN_FORWARD);			
		}		
		theForm.setUserID(userID);
		theForm.setFirsort(2);	//默认增加自助机构
		theForm.setType(GlbFinal.GROUP_PUBLIC);
		theForm.setStatus(GlbFinal.STS_NORMAL);
		
		request.setAttribute("theForm", theForm);
	
		return mapping.findForward(ADOPER_FORWARD);
	}	
	
	/**
	 *添加群组
	 */
	public ActionForward adadd(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		
		String path = (String)request.getSession().getServletContext().getRealPath("/");

		ReturnMessage msg  = new ReturnMessage();
		
		service.add(theForm,path, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		theForm.setQryFirs(2);
		
		request.setAttribute("theForm", theForm);
		
		return zizhu(mapping,form,request,response);
		
	}	
	/**
	 *添加群组
	 */
	public ActionForward add(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		
		String path = (String)request.getSession().getServletContext().getRealPath("/");

		ReturnMessage msg  = new ReturnMessage();
		
		service.add(theForm,path, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}else
		{
			msg.setMsg(" 创建部落成功！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl(GlbFinal.FOLDER_INSTALL + "/shequ.do?action=home&villageID=" + theForm.getVillageID());
			return showMsg(hmb , request , response , mapping);
		}
	}	
	
	/**
	 * 跳转到显示页面
	 */
	public ActionForward addPage(ActionMapping mapping, ActionForm form,
			 				 	 HttpServletRequest request , 
			 				 	 HttpServletResponse response)  
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		ReturnMessage msg  = new ReturnMessage();
	
		if(theForm.getVillageID() == 0) 
		{
			msg.setMsg("社区信息不存在");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}	
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0){
			
			return mapping.findForward(LOGIN_FORWARD);			
		}		
		theForm.setUserID(userID);
		
		request.setAttribute("theForm", theForm);
	
		return mapping.findForward(OPER_FORWARD);
	}	
	/**
	 *发送邀请Email
	 */
	public ActionForward email(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		
		String path = (String)request.getSession().getServletContext().getRealPath("/");

		ReturnMessage msg  = new ReturnMessage();
		
		service.sendEmail(theForm,path, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}else{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage("邮件发送成功！");
			hmb.setForwardUrl("/group.do?action=get&groupID="+ theForm.getGroupID());
			return showMsg(hmb , request , response , mapping);				
		}

	}	
	/**
	 *修改群组
	 */
	public ActionForward update(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		GroupsForm theForm = (GroupsForm) form;
		
		String path = (String)request.getSession().getServletContext().getRealPath("/");
		ReturnMessage msg  = new ReturnMessage();
		
		service.update(theForm,path, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		request.setAttribute("theForm", theForm);
		
		return get( mapping, form,  request, response);
	}
}
